﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;
using PBOffice.Models;

public partial class SystemManager_RoleRight : System.Web.UI.Page
{
    List<RoleRight> list;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int roleId = Convert.ToInt32(Request.QueryString["id"]);
            this.lbRoelName.Text = new RoleInfoManager().GetRoleInfoById(roleId).RoleName;
            list = new RoleRightManager().GetRoleRightByRoleId(roleId);
            foreach (RoleRight item in list)
            {
                InitRoleRight(item.NodeId);
            }
        }

    }
    private void InitRoleRight(int nodeId)
    {
        if (nodeId == 101001)
        {
            this.cbBranch.Checked = true;
        }
        if (nodeId == 101002)
        {
            this.cbDepartment.Checked = true;
        }
        if (nodeId == 101003)
        {
            this.cbPosition.Checked = true;
        }
        if (nodeId == 101004)
        {
            this.cbStaff.Checked = true;
        }
        if (this.cbBranch.Checked == true || this.cbDepartment.Checked == true || this.cbPosition.Checked == true || this.cbStaff.Checked == true)
        {
            this.cbPersonal.Checked = true;
        }
        if (nodeId == 102001)
        {
            this.CheckBox6.Checked = true;
        }
        if (nodeId == 102002)
        {
            this.CheckBox7.Checked = true;
        }
        if (nodeId == 102003)
        {
            this.CheckBox9.Checked = true;
        }
        if (this.CheckBox6.Checked == true || this.CheckBox7.Checked == true || this.CheckBox9.Checked == true)
        {
            this.CheckBox5.Checked = true;
        }
        if (nodeId == 103001)
        {
            this.CheckBox11.Checked = true;
        }
        if (nodeId == 103002)
        {
            this.CheckBox12.Checked = true;
        }
        if (nodeId == 103003)
        {
            this.CheckBox13.Checked = true;
        }
        if (this.CheckBox11.Checked == true || this.CheckBox12.Checked == true || this.CheckBox13.Checked == true)
        {
            this.CheckBox10.Checked = true;
        }
        if (nodeId == 104001)
        {
            this.CheckBox15.Checked = true;
        }
        if (nodeId == 104002)
        {
            this.CheckBox16.Checked = true;
        }
        if (this.CheckBox15.Checked == true || this.CheckBox16.Checked == true)
        {
            this.CheckBox14.Checked = true;
        }

        if (nodeId == 105001)
        {
            this.CheckBox18.Checked = true;
        }
        if (nodeId == 105002)
        {
            this.CheckBox19.Checked = true;
        }
        if (nodeId == 105003)
        {
            this.CheckBox20.Checked = true;
        }
        if (nodeId == 105004)
        {
            this.CheckBox21.Checked = true;
        }
        if (this.CheckBox18.Checked == true || this.CheckBox19.Checked == true || this.CheckBox20.Checked == true || this.CheckBox21.Checked == true)
        {
            this.CheckBox17.Checked = true;
        }

        if (nodeId == 106001)
        {
            this.CheckBox23.Checked = true;
        }
        if (nodeId == 106002)
        {
            this.CheckBox24.Checked = true;
        }
        if (nodeId == 106003)
        {
            this.CheckBox25.Checked = true;
        }
        if (nodeId == 106004)
        {
            this.CheckBox26.Checked = true;
        }
        if (nodeId == 106005)
        {
            this.CheckBox27.Checked = true;
        }
        if (this.CheckBox23.Checked == true || this.CheckBox24.Checked == true || this.CheckBox25.Checked == true || this.CheckBox26.Checked == true || this.CheckBox27.Checked == true)
        {
            this.CheckBox22.Checked = true;
        }

        if (nodeId == 107001)
        {
            this.CheckBox29.Checked = true;
        }
        if (nodeId == 107002)
        {
            this.CheckBox30.Checked = true;
        }
        if (nodeId == 107003)
        {
            this.CheckBox31.Checked = true;
        }
        if (this.CheckBox29.Checked == true || this.CheckBox30.Checked == true || this.CheckBox31.Checked == true)
        {
            this.CheckBox28.Checked = true;
        }

        if (nodeId == 108001)
        {
            this.CheckBox33.Checked = true;
        }
        if (nodeId == 108002)
        {
            this.CheckBox34.Checked = true;
        }
        if (this.CheckBox33.Checked == true || this.CheckBox34.Checked == true)
        {
            this.CheckBox32.Checked = true;
        }

        if (nodeId == 109001)
        {
            this.CheckBox36.Checked = true;
        }
        if (nodeId == 109002)
        {
            this.CheckBox37.Checked = true;
        }
        if (this.CheckBox36.Checked == true || this.CheckBox37.Checked == true)
        {
            this.CheckBox35.Checked = true;
        }
        if (nodeId == 110001)
        {
            this.CheckBox39.Checked = true;
            this.CheckBox38.Checked = true;
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        new RoleRightManager().DeleteRoleRight(Convert.ToInt32(Request.QueryString["id"]));
        RoleRight role = new RoleRight();
        role.RoleId = Convert.ToInt32(Request.QueryString["id"]);
        if (this.cbBranch.Checked == true)
        {
            role.NodeId = 101001;
            new RoleRightManager().Add(role);

        }
        if (this.cbBranch.Checked == true)
        {
            role.NodeId = 101002;
            new RoleRightManager().Add(role);
        }
        if (this.cbBranch.Checked == true)
        {
            role.NodeId = 101003;
            new RoleRightManager().Add(role);
        }
        if (this.cbBranch.Checked == true)
        {
            role.NodeId = 101004;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox6.Checked == true)
        {
            role.NodeId = 102001;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox7.Checked == true)
        {
            role.NodeId = 102002;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox9.Checked == true)
        {
            role.NodeId = 102003;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox11.Checked == true)
        {
           role.NodeId= 103001;
           new RoleRightManager().Add(role);
        }
        if (this.CheckBox12.Checked == true)
        {
            role.NodeId = 103002;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox13.Checked == true)
        {
            role.NodeId = 103003;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox15.Checked == true)
        {
            role.NodeId = 104001;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox16.Checked == true)
        {
            role.NodeId = 104002;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox18.Checked == true)
        {
            role.NodeId = 105001;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox19.Checked == true)
        {
            role.NodeId = 105002;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox20.Checked == true)
        {
            role.NodeId =105003;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox21.Checked == true)
        {
            role.NodeId = 105004;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox23.Checked == true)
        {
            role.NodeId = 106001;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox24.Checked == true)
        {
            role.NodeId = 106002;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox25.Checked == true)
        {
            role.NodeId =106003;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox26.Checked == true)
        {
            role.NodeId = 106004;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox27.Checked == true)
        {
            role.NodeId = 106005;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox29.Checked == true)
        {
            role.NodeId = 107001;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox30.Checked == true)
        {
            role.NodeId = 107002;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox31.Checked == true)
        {
            role.NodeId = 107003;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox33.Checked == true)
        {
            role.NodeId= 108001;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox34.Checked == true)
        {
            role.NodeId = 108002;
            new RoleRightManager().Add(role);
        }
        
        if (this.CheckBox36.Checked == true)
        {
            role.NodeId = 109001;
            new RoleRightManager().Add(role);
        }
        if (this.CheckBox37.Checked == true)
        {
            role.NodeId = 109002;
            new RoleRightManager().Add(role);
        }
        if ( this.CheckBox39.Checked == true)
        {
            role.NodeId = 110001;
            new RoleRightManager().Add(role);
           
        }

    }


}